<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">
	window.onload = function (){
		//标签名称
		//var aDiv = document.querySelectorAll('div');

		//.class名称
		var aDiv = document.querySelectorAll('.box');

		/*
			IE7及以下不支持querySelectorAll
		*/

		for (var i = 0; i < aDiv.length; i++) {
			aDiv[i].style.backgroundColor = 'red';
		};		
	}
	</script>
</head>
<body>
	<div class="box">div1</div>
	<div class="box">div2</div>
</body>
</html>